<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;

        }

        .box {
            width: 100px;
            height: 100px;
            background-color: aquamarine;
            margin: 100px auto;
            /* border: 8px solid #cccccc; */
            border-radius: 50%;
            position: relative;
        }

        span {
            display: block;
            font-size: 55px;
            width: 100%;
            height: 100%;
            position: absolute;
            top: 0;
            left: 0;
            text-align: center;
            line-height: 100px;
        }

        #myCanvas {


            background-color: #cccccc;
            border-radius: 50%;


        }

        body {
            position: relative;
        }

        .btn {

            background-color: rgb(39, 207, 9);
        }

        input {
            margin-left: 500px;

        }
    </style>
</head>

</head>

<body>
    <div class="box">
        <span class="span-class"></span>
        <canvas id="myCanvas" width="100" height="100">

    </div>
    <input type="text">
    <button class="btn">开始按钮</button>
    <script>
        let c = document.getElementById("myCanvas");
        let button = document.getElementsByTagName("button")[0];
        let input = document.getElementsByTagName("input")[0];
        let span = document.getElementsByTagName("span")[0];

        let r = Math.floor(c.width / 2);
        let ctx = c.getContext("2d");


        button.onclick = function () {
            clearInterval(timer);
            let num = input.value * 1;
            span.innerHTML = num;
            let n = -0.5 * Math.PI;
            var timer = setInterval(function () {
                ctx.clearRect(0, 0, 580, 580);
                n += (2 * Math.PI / num);
                span.innerHTML -= 1;
                ctx.beginPath();
                ctx.arc(50, 50, r, n, -0.5 * Math.PI, true);
                ctx.strokeStyle = "red";
                ctx.lineWidth = 10;
                ctx.stroke();
                if (span.innerHTML == 0) {
                    clearInterval(timer);
                }
            }, 1000)

        }
    </script>
</body>

</html>